package com.mxj.web;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author yuisama
 * @date 2023/02/06 19:57
 **/
@Controller
public class DemoController {
    //默认的  支持HTTP所有的方法
    @RequestMapping("/hello")
    //根据请求 + requestMapping 可以确定本次请求
    public String hello(Model model){
        Student student = new Student("门门","明天会更好","2001-04-15");

        model.addAttribute("person",student);
        //添加一个student 代表 person


        return "just-a-view";
    }



    //只支持 get方法
    @GetMapping("/hello4")
    //添加这个，使得这个方法只支持Get
    public String hello4(Model model){
        Student student = new Student("喜羊羊","我喜欢打篮球","2001-04-15");

        model.addAttribute("person",student);
        return "just-a-view";
    }


    //只支持 post方法
    @PostMapping("/hello5")
    //添加这个，使得这个方法只支持Get
    public String hello5(Model model){
        Student student = new Student("喜羊羊","我喜欢打篮球","2001-04-15");

        model.addAttribute("person",student);
        return "just-a-view";
    }

    //只支持HTTP get方法
    @RequestMapping(value = "/hello2",method = RequestMethod.GET)
    //添加这个，使得这个方法只支持Get
    public String hello2(Model model){
        Student student = new Student("喜羊羊","我喜欢打篮球","2001-04-15");

        model.addAttribute("person",student);
        return "just-a-view";
    }


    //支持HTTP get方法  和 POST方法
    @RequestMapping(value = "/hello3",method = {RequestMethod.GET,RequestMethod.POST})
    //添加这个，使得这个方法只支持Get
    public String hello3(Model model){
        Student student = new Student("暖羊羊","我是中锋","2001-04-15");

        model.addAttribute("person",student);
        return "just-a-view";
    }

}

